#ifndef CONTROL_HEADER_FILE
#define CONTROL_HEADER_FILE


/** All functctrlns return value
 * 0:  success
 * !0: failure
 */

// ctrl模块初始化
int ctrl_module_init();

// ctrl模块关闭
int ctrl_module_close();

// 重启gige
int ctrl_gige_reboot();

// 红灯开关
#define ctrl_turn_on_redlight() ctrl_relay_on(0)
#define ctrl_turn_off_redlight() ctrl_relay_off(0)

// 黄灯开关
#define ctrl_turn_on_yellowlight() do{\
    ctrl_relay_on(1);\
    __log_mesg("Turn on yellowlight.\n");\
}while(0)

#define ctrl_turn_off_yellowlight() do{\
    ctrl_relay_off(1);\
    __log_mesg("Turn off yellowlight.\n");\
}while(0)

// 声音开关
#define ctrl_turn_on_sound() ctrl_relay_on(2)
#define ctrl_turn_off_sound() ctrl_relay_off(2)

// 打开红灯+声音
#define ctrl_turn_on_soundlight() do{\
    ctrl_relay_on(0);\
    ctrl_relay_on(2);\
    __log_mesg("Turn on redlight and sound.\n");\
}while(0)\

// 关闭红灯+声音
#define ctrl_turn_off_soundlight() do{\
    ctrl_relay_off(0);\
    ctrl_relay_off(2);\
    __log_mesg("Turn off redlight and sound.\n");\
}while(0)\

// 相机光源是常闭，所以turn_on对应relay_off，turn_off对应relay_on
#define ctrl_turn_on_camlight()  do{\
    ctrl_relay_off(3);\
    __log_mesg("Turn on camlight.\n");\
}while(0)\

#define ctrl_turn_off_camlight() do{\
    ctrl_relay_on(3);\
    __log_mesg("Turn off camlight.\n");\
}while(0)\

// 东曲皮带撕裂清扫器执行
// 正向运动(红灯指令控制)
#define CLEAN_FORWARD(t) do{\
    __log_mesg("CLEAN_FORWARD begin.\n");\
    ctrl_turn_on_redlight();\
    sleep(t);\
    ctrl_turn_off_redlight();\
    __log_mesg("CLEAN_FORWARD end.\n");\
}while(0)

// 反向运动(黄灯指令控制)
#define CLEAN_BACKWARD(t) do{\
    __log_mesg("CLEAN_BACKWARD begin.\n");\
    ctrl_turn_on_yellowlight();\
    sleep(t);\
    ctrl_turn_off_yellowlight();\
    __log_mesg("CLEAN_BACKWARD end.\n");\
}while(0)

// 打开继电器
int ctrl_relay_on(int relay);

// 关闭继电器
int ctrl_relay_off(int relay);

// 打开所有继电器
int ctrl_relay_on_all();

// 关闭所有继电器
int ctrl_relay_off_all();

void ctrl_test();
 
#endif